package sy.controller.demo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import sy.controller.base.BaseController;
import sy.model.demo.DemoUser;
import sy.pageModel.base.JsonResult;
import sy.pageModel.base.PageResult;
import sy.service.base.BaseService;
import sy.service.demo.DemoUserService;

/**
 * 用户控制器
 * 
 * @author 孙宇
 *
 */
@Controller
@RequestMapping("/demoUserController")
public class DemoUserController extends BaseController<DemoUser, Long> {

	@Resource(name = "demoUserService")
	@Override
	public void setService(BaseService<DemoUser, Long> service) {
		super.service = service;
	}

	/**
	 * 前台页面name="demoUser."开头的，会自动封装到DemoUser对象里面
	 * 
	 * @param binder
	 */
	@InitBinder("demoUser")
	public void initBinderDemoUser(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("demoUser.");
	}

	@RequestMapping("/save")
	@ResponseBody
	public JsonResult save(DemoUser demoUser) {
		return super.save(demoUser);
	}

	@RequestMapping("/delete")
	@ResponseBody
	public JsonResult delete(Long id) {
		return super.delete(id);
	}

	@RequestMapping("/update")
	@ResponseBody
	public JsonResult update(DemoUser demoUser) {
		return super.update(demoUser);
	}

	@RequestMapping("/get")
	@ResponseBody
	public JsonResult get(Long id) {
		return super.get(id);
	}

	@RequestMapping("/find")
	@ResponseBody
	public PageResult find(HttpServletRequest request) {
		return super.find(request);
	}

	@RequestMapping("/getBySql")
	@ResponseBody
	public JsonResult getBySql(Long id) {
		JsonResult j = new JsonResult();
		j.setSuccess(true);
		j.setObj(((DemoUserService) service).getBySql(id));// 自定义接口，基类没有提供这个接口
		return j;
	}

}
